package cn.brondfish.icedfish;

import android.app.Application;
import android.content.SharedPreferences;
import android.util.Log;

import androidx.appcompat.app.AppCompatDelegate;
import androidx.lifecycle.LiveData;

import cn.brondfish.icedfish.common.Constants;
import cn.brondfish.icedfish.database.system.AppDatabase;
import cn.brondfish.icedfish.database.system.dao.SysUserDao;
import cn.brondfish.icedfish.database.system.entity.SysUser;
import cn.brondfish.icedfish.framework.util.BF_DeviceUniqueID;

public class IcedFishApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // 初始化数据库
        new Thread(() -> {
            // 从SharedPreferences中读取夜间模式设置
            SharedPreferences sharedPreferences = getSharedPreferences(Constants.PREFS_NAME, MODE_PRIVATE);
            int nightMode = sharedPreferences.getInt(Constants.NIGHT_MODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
            AppCompatDelegate.setDefaultNightMode(nightMode);
            SysUserDao sysUserDao = AppDatabase.getDatabase(this).sysUserDao();
            String device = BF_DeviceUniqueID.generateUniqueID(this);
            if(!sysUserDao.countUsers()){
                SysUser user = new SysUser();
                user.setDevice(device);
                user.setDelFlag("0");
                user.setStatus("0");
                user.setUserId(0L);
                user.setDeptId(0L);
                user.setToken("");
                sysUserDao.insert(user);
            }
        }).start();
    }
}
